package org.finesys.chat.core.base.document.splitter;

import org.finesys.chat.core.base.document.tokenizer.Tokenizer;

public class DocumentByParagraphSplitter extends HierarchicalDocumentSplitter {

    public DocumentByParagraphSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars) {
        super(maxSegmentSizeInChars, maxOverlapSizeInChars, (Tokenizer) null, (DocumentSplitter) null);
    }

    public DocumentByParagraphSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars, DocumentSplitter subSplitter) {
        super(maxSegmentSizeInChars, maxOverlapSizeInChars, (Tokenizer) null, subSplitter);
    }

    public DocumentByParagraphSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, Tokenizer tokenizer) {
        super(maxSegmentSizeInTokens, maxOverlapSizeInTokens, tokenizer, (DocumentSplitter) null);
    }

    public DocumentByParagraphSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, Tokenizer tokenizer, DocumentSplitter subSplitter) {
        super(maxSegmentSizeInTokens, maxOverlapSizeInTokens, tokenizer, subSplitter);
    }

    /**
     * 将字符串按双换行符进行分割，并返回分割后的字符串数组。
     *
     * @param text 需要分割的字符串
     * @return 字符串数组，包含分割后的各个子字符串
     */
    public String[] split(String text) {
        return text.split("\\s*(?>\\R)\\s*(?>\\R)\\s*");
    }

    public String joinDelimiter() {
        return "\n\n";
    }

    protected DocumentSplitter defaultSubSplitter() {
        return new DocumentBySentenceSplitter(this.maxSegmentSize, this.maxOverlapSize, this.tokenizer);
    }
}
